package com.dlz.systemshop.service.impl;


import com.dlz.systemshop.mapper.AdminMapper;
import com.dlz.systemshop.pojo.Admin;
import com.dlz.systemshop.service.AdminService;
import com.dlz.systemshop.utils.EncryptionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin findAdminByUserName(String userName) {
        return adminMapper.findAdminByUserName(userName);
    }

    @Override
    public boolean validateLogin(String userName, String passWord) {
        Admin admin = findAdminByUserName(userName);
        if(admin==null) {
            return false;
        }
        String s = EncryptionUtil.encryptPasswordWithSalt(passWord, admin.getSalt());
        System.out.println(s);
        return s.equals(admin.getPassWord());
    }
}
